package com.lagou.buffer;

import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;

/**
 * @description:
 * @author: yx
 * @date: 2021/11/5 14:39
 */
public class ReadBufferDemo {

    public static void main(String[] args) {
        ByteBuffer allocate = ByteBuffer.wrap("abcdefg".getBytes(StandardCharsets.UTF_8));
        System.out.println("position: " + allocate.position());
        System.out.println("limit: " + allocate.limit());
        System.out.println("remaining: " + allocate.remaining());
        System.out.println("capacity: " + allocate.capacity());
        System.out.println(new String(allocate.array(), StandardCharsets.UTF_8));
        while (allocate.hasRemaining()) {
            System.out.println(allocate.get());
        }
        System.out.println(allocate.get(2));
    }
}
